<?php
/**
 * Abstraktny singleton pattern
 * @author Tomas Srna
 * @package bakalarka
 */

abstract class Singleton
{
	private static $instances = array();
	protected function __construct() {}
	protected function __clone() {}
	
	/**
	 * Ziskanie instancie typicke pre Singleton
	 * @return stdClass Late-bind objekt
	 */
	final public static function instance()
	{
		$calledClass = get_called_class();
		if(!isset(self::$instances[$calledClass]))
			self::$instances[$calledClass] = new $calledClass();
		return self::$instances[$calledClass];
	}
	
	final public static function hasInstance()
	{
		$calledClass = get_called_class();
		return isset(self::$instances[$calledClass]);
	}
}
